package com.aaa.statistics.service.imp;

import com.aaa.entity.Registration;
import com.aaa.statistics.mapper.RegistrationMapper;
import com.aaa.statistics.service.WeekService;
import com.aaa.statistics.vo.RegistrationVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class WeekServiceImp implements WeekService {

    @Resource
    private RegistrationMapper registrationMapper;
    /**
     *查询医生工作量统计
     */
    @Override
    public Result<List<Registration>> findworkRegList(RegistrationVo registrationVo) {
        QueryWrapper<Registration> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(registrationVo.getDoctorName())){
            wrapper.like("doctor_name",registrationVo.getDoctorName());
        }
        //如果没有进行时间查询，则显示当天数据
        if (Objects.nonNull(registrationVo.getDateRange())&&registrationVo.getDateRange().length==2){
            wrapper.between("visit_date",registrationVo.getDateRange()[0],registrationVo.getDateRange()[1]);
        }else {
            //当天时间
            String beforeDay = LocalDate.now().minusDays(1).toString();
            String afterDay = LocalDate.now().plusDays(1).toString();
            wrapper.between("visit_date",beforeDay,afterDay);
        }
//        wrapper.eq("registrations_status",3);
        List<Registration> registrations = registrationMapper.selectList(wrapper);
        return new Result<>(200,"查询成功",registrations);
    }
    /**
     * 查询总体工作量统计
     */
    @Override
    public Result<List<Map<String, Object>>> findTotalworkRegList(RegistrationVo registrationVo) {
        String doctorName = registrationVo.getDoctorName();
        if (Objects.nonNull(registrationVo.getDateRange())&&registrationVo.getDateRange().length==2){
            String beforeDate = registrationVo.getDateRange()[0];
            String afterDate = registrationVo.getDateRange()[1];
            List<Map<String, Object>> mapList = registrationMapper.findTotalWorkList(doctorName,beforeDate,afterDate);
            return new Result<>(200,"查询成功",mapList);
        }else {
            //当天时间
            String beforeDate = LocalDate.now().minusDays(1).toString();
            String afterDate = LocalDate.now().plusDays(1).toString();
            List<Map<String, Object>> mapList = registrationMapper.findTotalWorkList(doctorName,beforeDate,afterDate);
            return new Result<>(200,"查询成功",mapList);
        }
    }
}
